/*******************************************************************************
 * This file is part of blueprint4j www.blueprint4j.org.
 * 
 *     blueprint4j is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     blueprint4j is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 * 
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with blueprint4j. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
/**
* This is an abstract message class no fields have been defined in this
* class
* $Log: MessageBlob.java,v $
* Revision 1.2  2004/09/14 13:55:11  travisb
* no message
*
* Revision 1.1.1.1  2004/04/22 12:56:14  travisb
* Fir
*
* Revision 1.1.1.1  2003/12/21 09:04:08  jaspervdb
* no message
*
* Revision 1.1.1.1  2003/10/20 15:30:48  travisb
* First import into CVS at Cellstop
*
* Revision 1.1.1.1  2003/03/30 15:25:28  tbulford
* no message
*
* Revision 1.1  2003/01/12 08:30:34  travis
* Import x MANY
*
* Revision 1.1.1.1  2002/12/16 22:14:01  jasper
* no message
*
* Revision 1.2  2002/09/29 17:17:15  travisb
* Template Processor Changes
*
* Revision 1.1  2002/02/20 13:30:43  JasperV
* First time add to new Applications layer
*
* Revision 1.4  2002/02/14 20:25:24  travisb
* Changes to message flow
*
* Revision 1.3  2002/02/14 08:41:18  travisb
* New Message type
*
* Revision 1.2  2002/02/12 16:57:29  JasperV
* Updated version
*
* Revision 1.1  2002/01/24 14:18:14  travisb
* First Version of the Application Layer
*
*/

package blueprint4j.messages;

import java.io.*;
import java.util.*;
import java.text.*;

import blueprint4j.utils.*;

public class MessageBlob extends Message {
	private ByteArrayOutputStream buffer=new ByteArrayOutputStream();
	private String name="Blob";

	public MessageBlob()
	throws ExceptionMessage {
	}

	public void setMessage(Properties props)
	throws ExceptionMessage {
		throw new ExceptionMessage("Blob Message does not support this Method");
	}


	public Properties getMessage()
	throws ExceptionMessage {
		throw new ExceptionMessage("Blob Message does not support this Method");
	}


	public String getMessageAsString()
	throws ExceptionMessage {
		throw new ExceptionMessage("Blob Message does not support this Method");
	}

	/**
	* Overloaded to return a more suitable name
	*/
	public String toString() {
		return name;
	}

	/**
	* Set this message name
	* @param
	*/
	public void setName(String p_name) {
		if (p_name == null) {
			name = "Blob";
		} else {
			name = p_name;
		}
	}


	/**
	* Set this message name
	*/
	public String getName() {
		return name;
	}

	/**
	* Sets a field definition
	* @param
	*/
	protected void setField( Field as_field )
	throws ExceptionMessage {
		throw new ExceptionMessage("Blob Message does not support this Method");
	}

	/**
	* Check is a field is defined
	* @param
	*/
	public boolean hasField( int field )
	throws ExceptionMessage {
		throw new ExceptionMessage("Blob Message does not support this Method");
	}


	/**
	* Check is a field is defined
	* @param
	*/
	public boolean hasField( String field )
	throws ExceptionMessage {
		throw new ExceptionMessage("Blob Message does not support this Method");
	}

	/**
	* Get the max width for the field
	* @param
	*/
	public int getMaxFieldWidth( String field )
	throws ExceptionMessage {
		throw new ExceptionMessage("Blob Message does not support this Method");
	}

	/**
	* Get the max width for the field
	* @param
	*/
	public int getMaxFieldWidth( int field )
	throws ExceptionMessage {
		throw new ExceptionMessage("Blob Message does not support this Method");
	}

	/**
	*/
	public void setType(String p_message_type )
	throws ExceptionMessage {
		throw new ExceptionMessage("Blob Message does not support this Method");
	}

	/**
	*/
	public String getType()
	throws ExceptionMessage {
		throw new ExceptionMessage("Blob Message does not support this Method");
	}

	public String get( int field_no )
	throws ExceptionMessage {
		throw new ExceptionMessage("Blob Message does not support this Method");
	}

	public String get( String field )
	throws ExceptionMessage {
		throw new ExceptionMessage("Blob Message does not support this Method");
	}

	public void set( int field_no, String p_value )
	throws ExceptionMessage {
		throw new ExceptionMessage("Blob Message does not support this Method");
	}

	public void set( String field, String p_value )
	throws ExceptionMessage {
		throw new ExceptionMessage("Blob Message does not support this Method");
	}

	public void setBinary( int field_no, byte[] p_value )
	throws ExceptionMessage {
		throw new ExceptionMessage("Blob Message does not support this Method");
	}

	public void setBinary( String field, byte[] p_value )
	throws ExceptionMessage {
		throw new ExceptionMessage("Blob Message does not support this Method");
	}

	public void read( InputStream input )
	throws ExceptionMessage, IOException {
		byte buf[]=new byte[1024];
		buffer=new ByteArrayOutputStream();
		for (int rsize=input.available();rsize>0;) {
			int r=rsize;
			Log.trace.out("Blob read size="+input.available());
			if (r>1024){
				r=1024;
			}
			int size=input.read(buf,0,r);
			rsize-=size;
			Log.trace.out("Blob read returned size="+size);
			buffer.write(buf,0,size);
		}
		Log.trace.out("Blob in size="+buffer.toByteArray().length);
		Log.trace.out(new String(buffer.toByteArray()));
	}

	public void write( OutputStream output )
	throws ExceptionMessage, IOException {
		Log.trace.out("Blob out size="+buffer.toByteArray().length);
		buffer.writeTo(output);
	}
}
